package com.hui.controller;

import com.hui.entity.Goods;
import com.hui.entity.Orders;
import com.hui.feign.GoodsFeign;
import com.hui.service.OrderService;
import com.hui.vo.OrderVo;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/09/17/8:26
 * @Description:
 */
@RequestMapping("order")
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("getOrder/{id}")
    public Orders getOrder(@PathVariable Integer id) {
        return orderService.getOrderById(id);
    }

    // 分页+条件查询订单信息
    @PostMapping("getOrderByCondition")
    public Map<String ,Object> getOrderByCondition(@RequestBody OrderVo orderVo){
        return orderService.getOrderByCondition(orderVo);
    }

    @Autowired
    private GoodsFeign goodsFeign;

    // 调用商品列表
    @GetMapping("getGoods/{id}")
    public Goods getGoods(@PathVariable Integer id) {
        return goodsFeign.getGoods(id);
    }


    // 获取商品微服务的端口，测试负载均衡
    @GetMapping("getGoodsPort")
    public String getGoodsPort(){
        return goodsFeign.getPort();
    }

//    // 从config server 中获取配置信息
//    @Value("${slogan}")
//    private String slogan;
//
//    @GetMapping("config")
//    public String config(){
//        return slogan;
//    }

}
